/*

This code creates a dataset for ASMB recipients, whether or not they responded
to the survey.  This is useful for Table B.2

*/



/**********************************************************************************************
Bring in data on ASMB recipients (i.e. responses & nonresponses) & merge to NMDB
**********************************************************************************************/

* asmb_nonresponses.xlsx is a file that Tim Critchfield sent me.
import excel "$DATA_OUT/ASMB_recipients/asmb_nonresponses.xlsx", sheet("Sheet1") firstrow clear

merge 1:1 loannb using "$NMDB/nmdb_20210113_v130_loans.dta", keep(master match) gen(merge_asmb_nonresponses) // Note about 700 ASMB nonresponses fail to  match to the NMDB.  According to Saty Patrabansh and Tim Critchield, these are loans dropped from the NMDB because they were not eligible for the NMDB, i.e. not closed-end first-lien mortgages, so it is safe for me to drop them as well.

keep if merge_asmb_nonresponses==3 // drop failed matches.

gen survey_year = 2016 if substr(survey_asmb,3,2)=="16"
replace survey_year = 2017 if substr(survey_asmb,3,2)=="17"
replace survey_year = 2018 if substr(survey_asmb,3,2)=="18"

/**********************************************************************************************
Create proxies using NMDB data
**********************************************************************************************/


** Also use the quarterly information to create the 60D proxy for liquidity shocks
do "$DOFILES/9999_create_60D_proxy_for_liquidity_shocks.do"

** Also use the quarterly information to create the MtM home equity proxies
global BKfine_bool = 0 // without ASMB responses we have no condo information so we cannot create the fine BK proxy
do "$DOFILES/9999_create_MtM_equity_proxies.do"

* Define defaulters
merge 1:1 loannb using "$NMDB/nmdb_20210113_v130_month2.dta", keep(match) nogen
do "$DOFILES/9999_define_defaulters.do"
gen in_default_sample = defaulter==1 & !mi(last_current_month_b4_default)


save "$DATA_OUT/NMDB_ASMB_recipients", replace
